﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace Elasticsearch.Synchronize.Repository.MongoDbDTO
{
    [BsonIgnoreExtraElements(true)]
    public class SynchronizeRuleDTO : BaseDTO
    {
        public string RuleId { get; set; }

        public string RuleMongoServerUrl { get; set; }

        public string RuleMongoDatabase { get; set; }

        public string RuleMongoCollection { get; set; }

        public string RuleFilter { get; set; }

        public List<string> RuleProjection { get; set; }

        public string RuleItemMongoServerUrl { get; set; }

        public string RuleItemMongoDatabase { get; set; }

        public string RuleItemMongoCollection { get; set; }

        public string RuleItemFilterTemplate { get; set; }

        public string RuleItemElasticsearchServerUrl { get; set; }

        public string RuleItemElasticsearchIndexName { get; set; }

        public string RuleItemElasticsearchTypeName { get; set; }

        public bool Enabled { get; set; }

        public void Test()
        {
            SynchronizeRuleDTO rule = new SynchronizeRuleDTO()
            {
                RuleId = Guid.NewGuid().GetHashCode().ToString(),
                RuleMongoServerUrl = "mongodb://root:_sys31UC@db251.31huiyi.com:27017",
                RuleMongoDatabase = "HeXinDB",
                RuleMongoCollection = "Events",
                RuleFilter = "{EventId:38096927}",
                RuleProjection = new List<string>()
                {
                    "EventId"
                },

                RuleItemMongoServerUrl = "mongodb://root:_sys31UC@db251.31huiyi.com:27017",
                RuleItemMongoDatabase = "HeXinDB",
                RuleItemMongoCollection = "EventJoins",
                RuleItemFilterTemplate = "{EventId:${EventId}}",
                RuleItemElasticsearchServerUrl = "http://es.31huiyi.com:9200",
                RuleItemElasticsearchIndexName = "hexindb_eventjoins",
                RuleItemElasticsearchTypeName = "EventJoins",
                Enabled = true
            };

            MongoDB.Driver.MongoClient _client =
                new MongoDB.Driver.MongoClient("mongodb://root:_sys31UC@192.168.10.222:27017");
            _client.GetDatabase("HeXinDB").GetCollection<SynchronizeRuleDTO>("SynchronizeRule").InsertOne(rule);
        }
    }
}